package com.newlink.building.main.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.newlink.building.common_base.model.bean.CateGorySecondItem
import com.newlink.building.common_base.model.bean.PropertyManagerData
import com.newlink.building.common_base.model.bean.RoomData
import com.newlink.building.main.databinding.ItemPropertyManagerBinding
import com.newlink.building.main.databinding.LayoutCategorySecondItemBinding


class Module_Main_CategorySecondItemAdapter : Module_Main_BaseRecyclerViewAdapter<CateGorySecondItem, ViewBinding>() {
    private val TYPE_ITEM_1: Int = 1
    private val TYPE_ITEM_2: Int = 2
    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int,
    ): ViewBinding {
        when (viewType) {
            TYPE_ITEM_1 -> {
                return LayoutCategorySecondItemBinding.inflate(layoutInflater, parent, false)
            }

            TYPE_ITEM_2 -> {
                return ItemPropertyManagerBinding.inflate(layoutInflater, parent, false)
            }
        }
        return LayoutCategorySecondItemBinding.inflate(layoutInflater, parent, false)
    }

//    override fun onBindDefViewHolder(
//        holder: BaseBindViewHolder<LayoutCategorySecondItemBinding>,
//        item: CateGorySecondItem?,
//        position: Int,
//    ) {
//
//
//        holder.binding?.apply {
////            tvRoomNumber.text = item?.roomNo
////            tvRoomName.text = item?.roomName
////            ViewUtils.setClipViewCornerRadius(tvTitle, dpToPx(8))
//        }
//
//    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: CateGorySecondItem?,
        position: Int,
    ) {
        when (holder.itemViewType) {
            TYPE_ITEM_1 -> {
                holder.binding as LayoutCategorySecondItemBinding
                holder.binding?.apply {
                    tvRoomNumber.text = (item as RoomData).roomNo
                    tvRoomName.text = item.roomName
                }
            }

            TYPE_ITEM_2 -> {
                holder.binding as ItemPropertyManagerBinding
                holder.binding?.apply {
//                    tvManagerName.text = (item as PropertyManagerData).name
                    tvManagerName.text = (item as PropertyManagerData).name
                }
            }
        }
    }

    override fun getItemViewType(position: Int): Int {
        val cateGorySecondItem = getData()[position]
//        return  cateGorySecondItem.type
        if (cateGorySecondItem is RoomData) {
            return TYPE_ITEM_1
        } else if (cateGorySecondItem is PropertyManagerData) {
            return TYPE_ITEM_2
        }
        return TYPE_ITEM_1
    }

}